﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using ElMexicanos.Base.Models;

namespace ElMexicanos.Components.Maps
{
    public class MapManager
    {

        public  Case[,] map;
        

        public MapManager(int resX, int resY)
        {
            map = new Case[12, 21];
            //map = new Case[longueur, largeur];
            chargementMap(resX, resY);

        }

        private void chargementMap(int resX, int resY)
        {
            int positionX;
            int positionY;
            string ligne;
            string colonne;
            string texture;
            string type;
            string orientation;
            string chemin;
            
            //Case[,] tableauDeCase = new Case[9,9];
            //List<List<Case>> mon_tableau = new List<List<Case>>();

            // mettre le chemin du fichier XML
            XDocument xdoc = XDocument.Load("Content/Maps/map2.xml");

            //Pour chaque case de mon XML
            foreach (var Case in xdoc.Root.Element("Mapping").Elements("Case"))
            {

                ligne = Case.Element("ligne").Value;
                colonne = Case.Element("colonne").Value;
                texture = Case.Element("Texture").Value;
                type = Case.Element("Type").Value;
                orientation = Case.Element("Orientation").Value;
                chemin = Case.Element("Chemin").Value;

                int IntLigne = Convert.ToInt32(ligne);
                int IntColonne = Convert.ToInt32(colonne);

                positionX = IntColonne * (resX/21); //Posission de la case en pixel
                positionY = IntLigne * (resY/12);

                map[IntLigne, IntColonne] = new Case(texture, type, orientation, chemin, positionX, positionY);

            }
        
        }


    }

}
